/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2008 www.pretty-tools.com
 */
function contextmenuGetTRObject()
{
    var oObj = window.event.srcElement;
    while (oObj.tagName != 'TR' && oObj.tagName != 'TABLE')
        oObj = oObj.parentElement;
    return oObj.tagName == 'TABLE' ? null : oObj;
}

function contextmenuGetTABLEObject(oObj)
{
    while (oObj != null && oObj.tagName != 'TABLE')
        oObj = oObj.parentElement;
    return oObj;
}

function contextmenuOnMouseOver()
{
    var oObj = contextmenuGetTRObject();
    if (oObj) oObj.style.backgroundColor = !oObj.disabled ? 'skyblue' : 'lightcoral';
}

function contextmenuOnMouseOut()
{
    var oObj = contextmenuGetTRObject();
    if (oObj) oObj.style.backgroundColor = '';
}

function contextmenuHideMenu(id)
{
    var menu = document.getElementById(id);
    if (menu) menu.style.visibility = 'hidden';
}

function contextmenuShowMenu(id)
{
    contextmenuHideMenu(id);
    var menu = document.getElementById(id);
    menu.style.left = window.event.x + document.body.scrollLeft;
    menu.style.top = window.event.y + document.body.scrollTop;
    menu.style.visibility = 'visible';
    window.event.cancelBubble = true;
    return false;
}

function contextmenuProcessHidden(id)
{
    var menu = document.getElementById(id);
    if (!menu)
        return;

    var trs = null;
    for (var i = 0; !trs && i <menu.childNodes.length; ++i)
    {
        if (menu.childNodes[i].tagName == "TR")
            trs = menu.childNodes[i];
    }
    if (!trs)
        return;

    for (;trs;trs = trs.nextSibling)
    {
        trs.style.display = !trs.hidden ? 'inline' : 'none';
    }
}
